<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>index</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="__STATIC__/xadmin/css/font.css">
        <link rel="stylesheet" href="__STATIC__/xadmin/css/xadmin.css">
          <script type="text/javascript" src="__STATIC__/xadmin/js/jquery_3.2.1.min.js"></script>
        <script src="__STATIC__/xadmin/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="__STATIC__/xadmin/js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>

    <body>
    <div class="x-nav">
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                           <button class="layui-btn" onclick="xadmin.open('添加菜单','{:url('menu/addmenu');}',500,500)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                        <form method="post" action="{:url('menu/index');}">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th width="30">排序</th>
                                  <th>名称</th>
                                  <th>规则</th>
                                  <th>状态</th>
                                  <th>操作</th>
                              </thead>
                              <tbody class="x-cate">
                              {volist  name="data" id="vo"}
                                <tr cate-id='{$vo.id}' fid='{$vo.pid}' >
                                  <td>
                                    <input type="text" class="layui-input x-sort" value="{$vo.sort}" name="sort[]">
                                    <input type="hidden" name="id[]" value="{$vo.id}" />
                                  </td>
                                  <td>
                                    <i class="layui-icon x-show" status='true'>&#xe623;</i>
                                    {$vo.title}
                                  </td>
                                  <td>{$vo.name}</td>
                                  <td>
                                    {if condition="$vo.status eq '1'"}
                                    <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>开启</em><i></i></div>
                                    {else /}
                                     <div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>停用</em><i></i></div>
                                    {/if}
                                  </td>
                                  <td class="td-manage">
                                    <a title="修改"  onclick="xadmin.open('修改菜单','{:url('menu/editmenu',array('id'=>$vo.id));}',500,500)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                 <a title="删除" onclick="del(this,'{$vo.id}','{$vo.title}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                  </td>
                                </tr>
                                {volist name="vo['two']" id="vot"}
                                <tr cate-id='{$vot.id}' fid='{$vot.pid}' >
                                  <td>
                                  <input type="text" class="layui-input x-sort" value="{$vot.sort}" name="sort[]">
                                    <input type="hidden" name="id[]" value="{$vot.id}" />
                                  </td>
                                  <td>
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                    <i class="layui-icon x-show" status='true'>&#xe623;</i>
                                    {$vot.title}
                                  </td>
                                  <td>{$vot.name}</td>
                                  <td>
                                    {if condition="$vot.status eq '1'"}
                                    <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>开启</em><i></i></div>
                                    {else /}
                                     <div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>停用</em><i></i></div>
                                    {/if}
                                  </td>
                                  <td class="td-manage">
                                  
                                     <a title="修改"  onclick="xadmin.open('修改菜单','{:url('menu/editmenu',array('id'=>$vot.id));}',500,500)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                     <a title="删除" onclick="del(this,'{$vot.id}','{$vot.title}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                  </td>
                                </tr>
                                {volist  name="vot['ree']" id="votr"}
                                <tr cate-id='{$votr.id}' fid='{$votr.pid}' >
                                  <td>
                                  <input type="text" class="layui-input x-sort" value="{$votr.sort}" name="sort[]">
                                    <input type="hidden" name="id[]" value="{$votr.id}" />
                                  </td>
                                  <td>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    ├{$votr.title}
                                  </td>
                                  <td>{$votr.name}</td>
                                  <td>
                                    {if condition="$votr.status eq '1'"}
                                    <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>开启</em><i></i></div>
                                    {else /}
                                     <div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>停用</em><i></i></div>
                                    {/if}
                                  </td>
                                  <td class="td-manage">
                                
                                    <a title="修改"  onclick="xadmin.open('修改菜单','{:url('menu/editmenu',array('id'=>$votr.id));}',500,500)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                     <a title="删除" onclick="del(this,'{$votr.id}','{$votr.title}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                  </td>
                                </tr>
                                  {/volist}
                                {/volist}
                              {/volist}
                              </tbody>
                            </table>
                            <button class="layui-btn" style="margin-top:5px;" type="submit">排序</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
          layui.use(['form'], function(){
            form = layui.form;
          });
          //删除
           function del(obj,id,name){
            layer.confirm('确认要删除'+name+'吗？',function(index){
                $.ajax({
                  type: "post",
                  url: "{:url('menu/delmenu');}",
                  data: {
                    id:id
                  },
                  success: function(data){
                    if(data.status == 1){
                        layer.msg('删除成功!',{icon:1,time:1000});
                        setTimeout(function(){
                            location.href="{:url('menu/index');}";
                        },1000);
                    }else{
                      layui.use('layer', function(){
                      var layer = layui.layer;
                      layer.msg(data.message,{
                        time: 2000
                      });
                    });
                  }
                  }
                });
                return false;
            });
          }

          // 分类展开收起的分类的逻辑
          $(function(){
            $("tbody.x-cate tr[fid!='0']").hide();
            // 栏目多级显示效果
            $('.x-show').click(function () {
                if($(this).attr('status')=='true'){
                    $(this).html('&#xe625;'); 
                    $(this).attr('status','false');
                    cateId = $(this).parents('tr').attr('cate-id');
                    $("tbody tr[fid="+cateId+"]").show();
               }else{
                    cateIds = [];
                    $(this).html('&#xe623;');
                    $(this).attr('status','true');
                    cateId = $(this).parents('tr').attr('cate-id');
                    getCateId(cateId);
                    for (var i in cateIds) {
                        $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                    }
               }
            })
          })
          var cateIds = [];
          function getCateId(cateId) {
              $("tbody tr[fid="+cateId+"]").each(function(index, el) {
                  id = $(el).attr('cate-id');
                  cateIds.push(id);
                  getCateId(id);
              });
          }
   
        </script>
    </body>
</html>
